  <template>
  <div class="Welcome">
    <el-container>
      <el-header>
        <div>
          <el-image style="width: 60px; height: 60px" :src="logosrc"></el-image>商场后台管理
        </div>
        <div>
          <el-button @click="tui">退出</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside :width="!isCollapse?'200px':'auto'">
          <el-radio-group v-model="isCollapse">
            <div @click="isCollapse=!isCollapse">|||</div>
          </el-radio-group>
          <el-menu
            router
            @select="activecai"
            :default-active="active"
            active-text-color="#66CCFF"
            :collapse="isCollapse"
            :unique-opened="true"
            background-color="#333744"
            text-color="#fff"
            class="el-menu-vertical-demo"
          >
            <el-submenu :index="item.order+''" v-for="item in leftlist" :key="item.id">
              <template slot="title">
                <i :class="item.incon"></i>
                <span slot="title" v-if="!isCollapse">{{item.authName}}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item :index="'/'+el.path" v-for="(el) in item.children" :key="el.id">
                  <i :class="el.incon"></i>
                  {{el.authName }}
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>

        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { left } from "@/ulits/api/Welcome/jurisdiction";
export default {
  name: "Welcome",
  data() {
    return {
      logosrc: require("@/assets/logo.png"),
      leftlist: [],
      leftincon: [
        "el-icon-user-solid",
        "el-icon-s-tools",
        "el-icon-s-goods",
        "el-icon-s-order",
        "el-icon-s-marketing",
      ],
      isCollapse: false,
      active: null,
    };
  },
  created() {
    // 获取左侧导航数据
    left().then((res) => {
      res.data.forEach((element, i) => {
        element.incon = this.leftincon[i];
        element.children.forEach((el) => {
          el.incon = "el-icon-s-operation";
        });
      });
      this.leftlist = res.data;
    });
    this.active = this.$store.state.activecai;
  },
  methods: {
    // 退出登录
    tui() {
      this.$store.commit("inittoken", null);
      this.$store.commit("initactivecai", null);
      this.$router.push("/");
      this.$message({
        message: "退出成功",
        type: "success",
      });
    },
    // 保存高亮记录
    activecai(path) {
      this.$store.commit("initactivecai", path);
    },
  },
  watch: {
    // $route: function (newVal, oldVal) {
    //   this.activecai = newVal.name;
    //   this.$store.commit("initactivecai", newVal.name);
    // },
  },
};
</script>

<style lang="scss" scoped>
.Welcome {
  .el-header {
    background-color: #666;
    color: #fff;
    height: 60px;
    line-height: 60px;
    display: flex;
    justify-content: space-between;
    padding: 0 20px;

    .el-image {
      margin-right: 20px;
      vertical-align: middle;
    }
    .el-button {
      background: #a6a9ad;
      color: #fff;
      border: 0;
    }
  }
  .el-aside {
    background-color: #333744;
    color: #333;
    text-align: center;
    line-height: 200px;
    overflow: hidden;
    overflow-y: auto;
    height: calc(100vh - 60px);
    .el-radio-button__inner,
    .el-radio-group {
      background-color: #999;
      color: #fff;
      line-height: 24px;
      font-size: 10px;
      text-align: center;
      letter-spacing: 0.2em;
      cursor: pointer;
      display: block;
    }

    .el-menu {
      background: #333744;
      border: 0;
      /deep/ {
        .el-submenu__title {
          color: #fff;
          text-align: left;
        }
        .el-menu-item-group {
          background: #333744;
          .el-menu-item {
            color: #fff;
          }
        }
      }
    }
  }
  .el-main {
    height: calc(100vh - 60px);
    background-color: #e9eef3;
    overflow: hidden;
    overflow-y: auto;
  }
}
</style>
<style >
.el-menu-item-group__title {
  padding: 0;
}
</style>